package com.danli;

import org.junit.jupiter.api.Test;

public class MyTest {


    @Test
    public  void testSingleton() {

        // 获取
//        Singleton instance = Singleton.INSTANCE;
//        Singleton instance2 = Singleton.INSTANCE;
//        System.out.println(instance==instance2);

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                Singleton instance = Singleton.INSTANCE;
                System.out.println(instance);
            }).start();
        }
    }

    @Test
    public void testSingleton2(){
//        Singleton2 instance = Singleton2.getInstance();
//        Singleton2 instance2 = Singleton2.getInstance();
//        System.out.println(instance==instance2);
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                Singleton2 instance = Singleton2.getInstance();
                System.out.println(instance);
            }).start();
        }

    }

    @Test
    public void testSingleton4(){
//        Singleton4 singleton4 = Singleton4.getInstance();
//        Singleton4 singleton5 = Singleton4.getInstance();
//        System.out.println(singleton4==singleton5);

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                Singleton4 instance = Singleton4.getInstance();
                System.out.println(instance);
            }).start();
        }

    }


    @Test
    public void testSingleton5(){
//        Singleton4 singleton4 = Singleton4.getInstance();
//        Singleton4 singleton5 = Singleton4.getInstance();
//        System.out.println(singleton4==singleton5);

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                Singleton5 instance = Singleton5.getInstance();
                System.out.println(instance);
            }).start();
        }

    }



    @Test
    public void testSingleton6(){
//        Singleton4 singleton4 = Singleton4.getInstance();
//        Singleton4 singleton5 = Singleton4.getInstance();
//        System.out.println(singleton4==singleton5);

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                Singleton6 instance = Singleton6.getInstance();
                System.out.println(instance);
            }).start();
        }

    }

    @Test
    public void testSingleton7(){
//        Singleton4 singleton4 = Singleton4.getInstance();
//        Singleton4 singleton5 = Singleton4.getInstance();
//        System.out.println(singleton4==singleton5);

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                Singleton7 instance = Singleton7.getInstance();
                System.out.println(instance);
            }).start();
        }

    }
}
